//
//  NetWorkUtils.m
//  MeMeDaiSteward
//
//  Created by Mime97 on 16/1/22.
//  Copyright © 2016年 Mime. All rights reserved.
//

#import "NetWorkUtils.h"
#import "AFNetworking.h"

@implementation NetWorkUtils

static NetWorkUtils *newInstance = nil;
static dispatch_once_t predicate;

+(NetWorkUtils *)shareInstance
{
    dispatch_once(&predicate, ^{
        newInstance=[[NetWorkUtils alloc]init];
    });
    return newInstance;
}

-(void)checkNetWorkingStatus:(void (^)(NetworkStatus))block
{
    __block NetworkStatus netStatus;
    
    [[AFNetworkReachabilityManager sharedManager]setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
        NSLog(@"Reachability: %@", AFStringFromNetworkReachabilityStatus(status));
        switch (status) {
            case AFNetworkReachabilityStatusReachableViaWWAN:
                netStatus = NetworkStatusViaWWAN;
                break;
            case AFNetworkReachabilityStatusReachableViaWiFi:
                netStatus = NetworkStatusViaWiFi;
                //                [operationQueue setSuspended:NO];
                break;
            case AFNetworkReachabilityStatusNotReachable:
                netStatus = NetworkStatusNotReachable;
                //                [operationQueue cancelAllOperations];
                break;
            default:
                //                [operationQueue setSuspended:YES];
                break;
        }
        if (block) {
            block(netStatus);
        }
    }];
    
    [[AFNetworkReachabilityManager sharedManager] startMonitoring];
    
}
@end
